package com.shinow.capacitor.plusins.decard;

import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
import com.shinow.capacitor.plusins.decard.f11.F11;

@CapacitorPlugin(name = "Decard")
public class DecardPlugin extends Plugin {

	private final F11 f11Implementation = new F11();

	@PluginMethod
	public void dcOpen(PluginCall call) {
		try {
			f11Implementation.dcOpen(getActivity(), call.getData());
			call.resolve();
		} catch (DecardRunTimeException e) {
			call.reject(e.getMessage(), e.getCode());
		}
	}

	@PluginMethod
	public void dcExit(PluginCall call) {
		try {
			f11Implementation.dcExit();
			call.resolve();
		} catch (DecardRunTimeException e) {
			call.reject(e.getMessage(), e.getCode());
		}
	}

	@PluginMethod
	public void readIdCard(PluginCall call) {
		try {
			JSObject Result = f11Implementation.readIdCard(call.getData());
			call.resolve(Result);
		} catch (DecardRunTimeException e) {
			call.reject(e.getMessage(), e.getCode());
		}
	}

	@PluginMethod
	public void readSocialSecurityCard(PluginCall call) {
		try {
			JSObject Result = f11Implementation.readSocialSecurityCard(call.getData());
			call.resolve(Result);
		} catch (DecardRunTimeException e) {
			call.reject(e.getMessage(), e.getCode());
		}
	}

	@PluginMethod
	public void readQRCode(PluginCall call) {
		try {
			JSObject Result = f11Implementation.readQRCode(call.getData());
			call.resolve(Result);
		} catch (DecardRunTimeException e) {
			call.reject(e.getMessage(), e.getCode());
		}
	}

	@PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
	public void loopReadIdCard(PluginCall call) {
		f11Implementation.loopReadIdCard(call);
	}

	@PluginMethod(returnType = PluginMethod.RETURN_NONE)
	public void stopLoopReadIdCard(PluginCall call) {
		f11Implementation.stopLoopReadIdCard();
	}

	@PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
	public void loopReadSocialSecurityCard(PluginCall call) {
		f11Implementation.loopReadSocialSecurityCard(call);
	}

	@PluginMethod(returnType = PluginMethod.RETURN_NONE)
	public void stopLoopReadSocialSecurityCard(PluginCall call) {
		f11Implementation.stopLoopReadSocialSecurityCard();
	}

	@PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
	public void loopReadQRCode(PluginCall call) {
		f11Implementation.loopReadQRCode(call);
	}

	@PluginMethod(returnType = PluginMethod.RETURN_NONE)
	public void stopLoopReadQRCode(PluginCall call) {
		f11Implementation.stopLoopReadQRCode();
	}
}
